var path = require('path');
var HtmlwebpackPlugin = require('html-webpack-plugin');
// var UglifyJsPlugin=require('webpack.optimize.UglifyJsPlugin');
var webpack = require('webpack');


//定义了一些文件夹的路径
var ROOT_PATH = path.resolve(__dirname);
var JS_PATH = path.resolve(ROOT_PATH, 'src', 'controller');
var CSS_PATH = path.resolve(ROOT_PATH, 'src', 'css');
var BUILD_PATH = path.resolve(ROOT_PATH);


module.exports = {
	//项目的文件夹 可以直接用文件夹名称 默认会找index.js 也可以确定是哪个文件名字
	entry: {
		question: JS_PATH + "/question",
		index: JS_PATH + "/index",
	},

	//输出的文件名 合并以后的js会命名为bundle.js
	output: {
		path: BUILD_PATH,
		filename: 'dist/[name].bundle.js'
	},

	//添加我们的插件 会自动生成一个html文件
	plugins: [
		new HtmlwebpackPlugin({
			template: 'html/index.html',
			file: 'index.html',
			inject: false,
		}),

		// new webpack.optimize.UglifyJsPlugin({
		// 	compress: {
		// 		warnings: false
		// 	}
		// }),

		//
		new webpack.optimize.CommonsChunkPlugin("dist/common.js", ["question",
			"index"
		]),

	],

	externals: {
		'jquery': 'jQuery',
	},

	//加载器配置
	loaders: [

		{
			test: /\.css$/,
			loaders: ['style', 'css'],
			include: CSS_PATH
		}, {
			test: /\.jsx?$/,
			loader: 'babel',
			include: JS_PATH,
			query: {
				presets: ['es2015']
			}
		}, {
			test: /\.(png|jpg)$/,
			loader: 'url-loader?limit=8192'
		}
	],

	devServer: {
		historyApiFallback: true,
		hot: true,
		inline: true,
		progress: true,
	},
};
